<?php
/**
 *
 * Created by PhpStorm.
 * User: jacky.yao
 * Date: 2020/5/20
 * Time: 20:11
 */

namespace Commands;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Lock\LockFactory;
//use Symfony\Component\Lock\Store\SemaphoreStore;
use Symfony\Component\Lock\Store\FlockStore;


class DemoCommand extends Command
{
    protected static $defaultName = 'app:demo';

    protected function configure()
    {
//        parent::configure(); // TODO: Change the autogenerated stub
        $this->setDescription('demo command')
            ->setHelp('no help now');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $store = new FlockStore();
        $factory = new LockFactory($store);
        $lock = $factory->createLock('my cron lock');
        if ($lock->acquire()) {
//        parent::execute($input, $output); // TODO: Change the autogenerated stub
            $output->writeln("<comment>hello</comment>");
            $output->writeln("<question>question</question>");
            $output->writeln("<error>error</error>");
//            $lock->release();
            sleep(10000);
            return 0;
        } else {
            $output->writeln('<error>script is running!</error>');
            exit();
        }
    }
}